import pandas as pd

# 读取数据
df = pd.read_excel('exam.xlsx')

# 获取所有题目名称
columns = df.columns

# 打开txt文件准备写入
with open('result.txt', 'w', encoding='utf-8') as f:
    # 计算两两题目的相关系数
    for i in range(len(columns)):
        for j in range(i+1, len(columns)):
            x = df[columns[i]]
            y = df[columns[j]]
            r = x.corr(y)
            f.write(f"r({columns[i]},{columns[j]}) = {r:.4f}\n")
